package com.guigu.guliorder.controller;


import com.guigu.gulicommon.entity.pojo.res.Res;
import com.guigu.guliorder.entity.OmsOrderItem;
import com.guigu.guliorder.entity.dto.InsertOrderItemBatchDto;
import com.guigu.guliorder.entity.dto.SelectOrderItemPagesDto;
import com.guigu.guliorder.entity.dto.UpdateOrderItemDto;
import com.guigu.guliorder.service.IOmsOrderItemService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;

import static com.guigu.gulicommon.constant.CheckParametersConstant.ORDER_ID_CANNOT_BE_NULL;

/**
 * 订单项信息
 * </p>
 *
 * @author 陈俊杰
 * @since 2024-08-15
 */
@Validated
@Log4j2
@RestController
@RequestMapping("/oms-order-item")
public class OmsOrderItemController {
    @Autowired
    private IOmsOrderItemService orderItemService;

    /**
     * 批量新增订单项(通用)
     *
     * @param dto 添加订单项的参数
     * @return vo 添加订单项的信息
     */
    @PostMapping
    public Res<OmsOrderItem> addBatch(@Validated @RequestBody ArrayList<InsertOrderItemBatchDto> dto) {
        log.info("批量新增订单项(通用)接口入参为:[{}]", dto);
        return orderItemService.addBatch(dto);
    }

    /**
     * 批量删除订单项(通用)
     *
     * @param ids 批量删除订单项的id集合
     * @return vo 被删除的订单项的信息
     */
    @DeleteMapping
    public Res<OmsOrderItem> removeByIdsBatch(
            @RequestParam(value = "ids")
            @NotNull(message = ORDER_ID_CANNOT_BE_NULL)
            Long[] ids
    ) {
        log.info("批量删除订单项(通用)接口入参为:[{}]", (Object) ids);
        return orderItemService.deleteByIdsBatch(ids);
    }

    /**
     * 修改订单项(通用)
     *
     * @param dto 修改订单项的参数
     * @return vo 修改后订单项的信息
     */
    @PutMapping
    public Res<OmsOrderItem> update(@Valid @RequestBody UpdateOrderItemDto dto) {
        log.info("修改订单项(通用)接口入参为:[{}]", dto);
        return orderItemService.update(dto);
    }

    /**
     * 分页查询订单项详情信息(通用)
     *
     * @param pagesDto 查询订单项的参数
     * @return vo 订单项详情的分页
     */
    @GetMapping
    public Res<OmsOrderItem> findPages(@Validated SelectOrderItemPagesDto pagesDto) {
        log.info("分页查询订单项详情信息(通用)接口入参为:[{}]", pagesDto);
        return orderItemService.findPages(pagesDto);
    }


}
